package com.fruit.auth.web.action;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import com.fruit.auth.model.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 *LoginInterceptor  登陆拦截器
 * @author zhaopeng
 *
 */
@Component
public class LoginInterceptor implements Interceptor
{
	private static final long serialVersionUID = -1621834907249654996L;

	@Override
	public void destroy()
	{

	}

	@Override
	public void init()
	{
		System.out.println("loginInterceptor....");
	}

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception
	{
		Object action=actionInvocation.getAction();
		if(action instanceof LoginAction)
		{
			return actionInvocation.invoke();
		}
		else
		{
			User user=(User) ServletActionContext.getRequest().getSession().getAttribute("user");
			if(null==user)
			{
				return "login";
			}
			else
			{
				return actionInvocation.invoke();
			}
		}
	}

	

}
